<template>
  <div class="app-container">
    <el-form ref="formSearch" :model="searchForm" label-width="100px">
      <el-row>
        <el-col :span="19">
          <el-row class="form_table">
            <el-col :span="6">
              <el-form-item :label="$t('processTask.no')" prop="processNo">
                <el-input v-model="searchForm.processNo" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item :label="$t('processTask.title')" prop="title">
                <el-input v-model="searchForm.title" clearable />
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="5" style="text-align: center">
          <el-button
            type="primary"
            @click="
              searchForm.pageNumber = 1
              getData()
            "
          >{{ $t('btn.query') }}</el-button>
          <el-button type="danger" @click="resetForm('formSearch')">{{ $t('btn.reset') }}</el-button>
        </el-col>
      </el-row>
    </el-form>
    <el-table stripe :data="tableList" border @selection-change="handleSelectionChange">
      <el-table-column fixed type="selection" width="50" center />

      <el-table-column :label="$t('processTask.no')" min-width="140" align="center">
        <template slot-scope="scope">
          <el-link type="primary" @click="handlerTask(scope.row)">{{ scope.row.processVariables.processNo }}</el-link>
        </template>
      </el-table-column>
      <!--<el-table-column prop="id" :label="$t('process.id')" min-width="160" align="center" />-->
      <el-table-column prop="processVariables.title" :label="$t('processTask.title')" min-width="140" align="center" />
      <el-table-column prop="name" :label="$t('process.name')" min-width="110" align="center" />
      <el-table-column prop="createTime" :label="$t('table.createTime')" min-width="90" align="center" />
    </el-table>
    <el-pagination v-show="total > 0" background :current-page.sync="searchForm.pageNumber" :page-sizes="$pageSizeAll" :page-size="searchForm.pageSize" layout="total, prev, pager, next, jumper, sizes" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    <Designer v-if="isDesignerPopup" ref="designer" />
  </div>
</template>
<script>
import { runtimeTaskPage, addProcess, deleteProcess, startProcess } from '@/api/flowable'
import Designer from '@/components/Flowable/Designer'
export default {
  name: 'Running',
  components: { Designer },
  data() {
    return {
      isDesignerPopup: false,
      id: '',
      treeDialog: false,
      selectedList: [],
      searchForm: {
        processNo: null,
        title: null,
        pageNumber: 1,
        pageSize: 10,
      },
      tableList: [],
      total: 0,
    }
  },
  created() {
    this.getData()
  },
  methods: {
    startProcess() {
      this.basicDialog = true
    },
    // 重置
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.tableList = []
      this.total = 0
      this.getData()
    },
    // 查询
    async getData() {
      const { data, code } = await runtimeTaskPage(this.searchForm)
      if (code != '200') return
      this.tableList = data.records
      this.total = data.total
    },
    // 选择项改变时
    handleSelectionChange(val) {
      this.selectedList = val
    },

    handlerTask(row) {
      this.$router.push({ path: '/flowable/running/handler', query: { id: row.id }})
    },
    // 页码改变
    handleCurrentChange(pageNumber) {
      this.searchForm.pageNumber = pageNumber
      this.getData()
    },
    // 每页size改变时
    handleSizeChange(val) {
      this.searchForm.pageNumber = 1
      this.searchForm.pageSize = val
      this.getData()
    },
  },
}
</script>
